package com.whale.controller.admin;


import com.whale.dto.ReservePaymentDTO;
import com.whale.dto.ReserveSubmitDTO;
import com.whale.mapper.ReserveDetailMapper;
import com.whale.result.PageResult;
import com.whale.result.Result;
import com.whale.service.ReserveService;
import com.whale.vo.ReservePaymentVO;
import com.whale.vo.ReserveSubmitVO;
import com.whale.vo.ReserveVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@Api(tags="用户预约接口")
@RestController("userReserveController")
@RequestMapping("/user/reserve")
@Slf4j
public class ReserveController {


    @Autowired
    private ReserveDetailMapper reserveDetailMapper;
    @Autowired
    private ReserveService reserveService;
    /**
     * 用户预约
     * @param reserveSubmitDTO
     * @return
     * */
    @ApiOperation("用户预约")
    @PostMapping("/submit")
    public Result<ReserveSubmitVO> submit(@RequestBody ReserveSubmitDTO reserveSubmitDTO){
          ReserveSubmitVO reserveSubmitVO=reserveService.submitReserve(reserveSubmitDTO);
          return Result.success(reserveSubmitVO);

    }
    /**
     * 订单支付
     *
     * @param reservePaymentDTO
     * @return
     */
    @PutMapping("/payment")
    @ApiOperation("订单支付")
    public Result<ReservePaymentVO> payment(@RequestBody ReservePaymentDTO reservePaymentDTO) throws Exception {
        log.info("订单支付：{}", reservePaymentDTO);
        ReservePaymentVO reservePaymentVO = reserveService.payment(reservePaymentDTO);
        log.info("生成预支付交易单：{}", reservePaymentVO);
        return Result.success(reservePaymentVO);
    }

    /**
     * 历史预约查询
     *
     * @param page
     * @param pageSize
     * @param status   预约状态 1待付款 2已完成 3已取消
     * @return
     */
    @GetMapping("/historyReserve")
    @ApiOperation("历史预约查询")
    public Result<PageResult> page(int page, int pageSize, Integer status) {
        PageResult pageResult = reserveService.pageQuery4User(page, pageSize, status);
        return Result.success(pageResult);
    }
    /**
     * 查询预约详情
     *
     * @param id
     * @return
     */
    @GetMapping("/reserveDetail/{id}")
    @ApiOperation("查询预约详情")
    public Result<ReserveVO> details(@PathVariable("id") Long id) {
        ReserveVO reserveVO = reserveService.details(id);
        return Result.success(reserveVO);
    }

    /**
     * 用户取消预约
     *
     * @return
     */
    @PutMapping("/cancel/{id}")
    @ApiOperation("取消预约")
    public Result cancel(@PathVariable("id") Long id) throws Exception {
        reserveService.userCancelById(id);
        return Result.success();
    }



}
